if VoteVGUI then
	for k, v in pairs(VoteVGUI) do
		v:Remove()
		VoteVGUI[k] = nil
	end
end

if QuestionVGUI then
	for k, v in pairs(QuestionVGUI) do
		v:Remove()
		QuestionVGUI[k] = nil
	end
end

VoteVGUI = {}
QuestionVGUI = {}
PanelNum = 0

if LetterWritePanel then
	LetterWritePanel:Remove()
	LetterWritePanel = nil
end

function MsgDoVote(msg)
	local question = msg:ReadString()
	local voteid = msg:ReadString()
	local inputenabled = false

	if HelpToggled or GUIToggled then
		inputenabled = true
	end

	local panel = vgui.Create("Frame")
	panel:SetPos(3, ScrH() / 2 - 50)
	panel:SetName("Panel")
	panel:LoadControlsFromString([[
		"VotePanel"
		{
			"Panel"
			{
				"ControlName" "Panel"
				"fieldName" "Vote"
				"wide" "140"
				"tall" "140"
				"sizable" "0"
				"enabled" "1"
				"title" "VoteCop"
			}
		}
	]])
	panel:SetKeyboardInputEnabled(false)
	panel:SetMouseInputEnabled(inputenabled)
	panel:SetVisible(true)

	local label = vgui.Create("Label")
	label:SetParent(panel)
	label:SetPos(5, 30)
	label:SetSize(180, 40)
	label:SetText(question)
	label:SetVisible(true)

	local divider = vgui.Create("Divider")
	divider:SetParent(panel)
	divider:SetPos(2, 80)
	divider:SetSize(180, 2)
	divider:SetVisible(true)

	_G["YesVoteFunc" .. voteid] = function(msg)
		LocalPlayer():ConCommand("vote " .. voteid .. " 1\n")
	end

	local ybutton = vgui.Create("Button")
	ybutton:SetParent(panel)
	ybutton:SetPos(15, 100)
	ybutton:SetSize(40, 20)
	ybutton:SetCommand("!")
	ybutton:SetText("Yes")
	ybutton:SetActionFunction(_G["YesVoteFunc" .. voteid])
	ybutton:SetVisible(true)

	table.insert(VoteVGUI, ybutton)

	_G["NoVoteFunc" .. voteid] = function(msg)
		LocalPlayer():ConCommand("vote " .. voteid .. " 2\n")
	end

	local nbutton = vgui.Create("Button")
	nbutton:SetParent(panel)
	nbutton:SetPos(60, 100)
	nbutton:SetSize(40, 20)
	nbutton:SetCommand("!")
	nbutton:SetText("No")
	nbutton:SetActionFunction(_G["NoVoteFunc" .. voteid])
	nbutton:SetVisible(true)

	table.insert(VoteVGUI, nbutton)

	PanelNum = PanelNum + 1
	VoteVGUI[voteid .. "vote"] = panel
end
usermessage.Hook("DoVote", MsgDoVote)

function KillVoteVGUI(msg)
	local id = msg:ReadString()

	if VoteVGUI[id .. "vote"] then
		for k, v in pairs(VoteVGUI) do
			if v:GetParent() == VoteVGUI[id .. "vote"] then
				v:Remove()
				VoteVGUI[k] = nil
			end
		end

		VoteVGUI[id .. "vote"]:Remove()
		VoteVGUI[id .. "vote"] = nil
		PanelNum = PanelNum - 1
	end
end
usermessage.Hook("KillVoteVGUI", KillVoteVGUI)

function MsgDoQuestion(msg)
	local question = msg:ReadString()
	local quesid = msg:ReadString()
	local inputenabled = false

	if HelpToggled or GUIToggled then
		inputenabled = true
	end

	local panel = vgui.Create("Frame")
	panel:SetPos(3, ScrH() / 2 - 50)
	panel:SetName("Panel")
	panel:LoadControlsFromString([[
		"QuestionPanel"
		{
			"Panel"
			{
				"ControlName" "Panel"
				"fieldName" "Question"
				"wide" "380"
				"tall" "140"
				"sizable" "0"
				"enabled" "1"
				"title" "Question"
			}
		}
	]])
	panel:SetKeyboardInputEnabled(false)
	panel:SetMouseInputEnabled(inputenabled)
	panel:SetVisible(true)

	local label = vgui.Create("Label")
	label:SetParent(panel)
	label:SetPos(5, 30)
	label:SetSize(380, 40)
	label:SetText(question)
	label:SetVisible(true)

	local divider = vgui.Create("Divider")
	divider:SetParent(panel)
	divider:SetPos(2, 80)
	divider:SetSize(380, 2)
	divider:SetVisible(true)

	_G["YesQuesFunc" .. quesid] = function(msg)
		LocalPlayer():ConCommand("ans " .. quesid .. " 1\n")
	end

	local ybutton = vgui.Create("Button")
	ybutton:SetParent(panel)
	ybutton:SetPos(147, 100)
	ybutton:SetSize(40, 20)
	ybutton:SetCommand("!")
	ybutton:SetText("Yes")
	ybutton:SetActionFunction(_G["YesQuesFunc" .. quesid])
	ybutton:SetVisible(true)

	table.insert(QuestionVGUI, ybutton)

	_G["NoQuesFunc" .. quesid] = function(msg)
		LocalPlayer():ConCommand("ans " .. quesid .. " 2\n")
	end

	local nbutton = vgui.Create("Button")
	nbutton:SetParent(panel)
	nbutton:SetPos(192, 100)
	nbutton:SetSize(40, 20)
	nbutton:SetCommand("!")
	nbutton:SetText("No")
	nbutton:SetActionFunction(_G["NoQuesFunc" .. quesid])
	nbutton:SetVisible(true)

	table.insert(QuestionVGUI, nbutton)

	PanelNum = PanelNum + 1
	QuestionVGUI[quesid .. "ques"] = panel
end
usermessage.Hook("DoQuestion", MsgDoQuestion)

function KillQuestionVGUI(msg)
	local id = msg:ReadString()

	if QuestionVGUI[id .. "ques"] then
		for k, v in pairs(QuestionVGUI) do
			if v:GetParent() == QuestionVGUI[id .. "ques"] then
				v:Remove()
				QuestionVGUI[k] = nil
			end
		end

		QuestionVGUI[id .. "ques"]:Remove()
		QuestionVGUI[id .. "ques"] = nil
		PanelNum = PanelNum - 1
	end
end
usermessage.Hook("KillQuestionVGUI", KillQuestionVGUI)

function DoLetter(msg)
	LetterWritePanel = vgui.Create("Frame")
	LetterWritePanel:SetPos(ScrW() / 2 - 75, ScrH() / 2 - 100)
	LetterWritePanel:SetSize(150, 200)
	LetterWritePanel:SetMouseInputEnabled(true)
	LetterWritePanel:SetKeyboardInputEnabled(true)
	LetterWritePanel:SetVisible(true)
end
usermessage.Hook("DoLetter", DoLetter)

function TestVGUI( )
 
      local Frame = vgui.Create( "Frame" ); //Create a frame
      Frame:SetSize( 200, 505 ); //Set the size to 200x200
      Frame:SetPos( 100, 100 ); //Move the frame to 100,100
      Frame:SetVisible( true ); //Visible
      Frame:MakePopup( ); //Make the frame
      Frame:PostMessage( "SetTitle", "text", "0m3ga RP Menu" ); //Set the title to "This is the title"   
      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Banker" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 5 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/banker")
	            
          end
      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Hitman" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 30 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/hitman")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Spy" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 55 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/spy")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Ninja" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 80 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/ninja")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Hoe" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 105 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/hoe")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Citizen" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 130 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/citizen")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Vice President" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 155 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/votevice")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "President" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 180 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/votepresident")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Swat Sniper" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 205 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/voteswatsniper")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Secret Service" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 230 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/ss")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Chief of Police" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 255 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/chief")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Police" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 280 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/votecop")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Terrorist" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 305 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/terrorist")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "ISD" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 330 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/isd")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Zombie" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 355 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/zombie")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Medic" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 380 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/medic")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Cook" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 405 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/cook")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "SWAT" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 430 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/voteswat")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Gangster" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 455 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/gangster")
	            
          end

      local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
      Button:SetText( "Mob Boss" ); //Set the button's text to "Click me!"
      Button:SetPos( 30, 480 ); //Set the button's position relative to it's parent(Frame)
      Button:SetWide( 100 ); //Sets the width of the button you're making
          function Button:DoClick( ) //This is called when the button is clicked
                 
		RunConsoleCommand("say", "/mobboss")
	            
          end
end
    
concommand.Add( "rp_menu", TestVGUI ); 
